'use strict';
(function() {
	
	function initParams($scope, $state, Dialog, AppConfigConstant, HlCssTypesConstant, service){
		$scope.ip = $state.params.ip;
		$scope.port = $state.params.port;
		$scope.monitor = $state.params.monitor;
		$scope.name = $state.params.name;
		$scope.APP_BASE_PATH = AppConfigConstant.APP_BASE_PATH;
		$scope.hlCssTypes = HlCssTypesConstant;
		$scope.hlCssType = "default";
		$scope.loginfo = null;
	}
	
	function init($scope, $state, Dialog, service){
		if($scope.ip && $scope.port && $scope.monitor){
			service.get($scope.ip, $scope.port, $scope.monitor, $scope.name, function(rst){
				var strs = rst.data.split("\r\n");
				var loginfo = "";
				for(var i = 0; i < strs.length; i++){
					loginfo += jsonBeautify(strs[i]) + "\r\n";
				}
				$scope.loginfo = loginfo;
			});
		}else {
			Dialog.show("请求参数不正确！");
		}
	}
	
	function jsonBeautify(text) {
		if (typeof JSON === 'undefined' ){
			return text; 
		}else if ( typeof text === "string" ){
			try {
				return JSON.stringify(JSON.parse(text), null, 4);
			}catch(e){
				return text;
			}
		}else if ( typeof text === "object" ) {
			try {
				return JSON.stringify(text, null, 2);
			}catch(e){
				return text;
			}
		}
		return text;
	}
	
    ngApp.controller("apploginfoController", ["$scope", "$state", "Dialog", 'AppConfigConstant', "HlCssTypesConstant", "apploginfoService", function($scope, $state, Dialog, AppConfigConstant, HlCssTypesConstant, apploginfoService) {
    	initParams($scope, $state, Dialog, AppConfigConstant, HlCssTypesConstant, apploginfoService);
    	init($scope, $state, Dialog, apploginfoService);
    }]);

})();
